package com.longe.controller;

import com.longe.security.MyRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("clear")
public class ClearCacheController {

    @Autowired
    private MyRealm myRealm;

    /**
     * 清除当前登录用户的缓存
     * @return
     */
    @RequestMapping("cache/current")
    public String clearCacheCurrent(){

        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();

        myRealm.clearCache(principals);

        return "clear";
    }

    /**
     * 清除所有用户的缓存
     * @return
     */
    @RequestMapping("cache/all")
    public String clearCacheAll(){

        myRealm.clearAll();

        return "clear";
    }
}
